package com.example.librarymanagementsystem.model;

import com.example.librarymanagementsystem.enums.ResultStatus;
import lombok.Data;

@Data
public class Result<T> {
    private ResultStatus code;//业务码     不是HTTP状态码   200——成功   -2 失败    -1未登录
    private String errMsg;//错误信息        如果业务成功，errMsg为空
    private T data;

    public static<T> Result success(T data){
        //参数校验自己补充
        Result result = new Result<>();
        result.setCode(ResultStatus.SUCCESS);
        result.setData(data);
        return result;
    }
    public static <T> Result noLogin(){
            Result result = new Result<>();
            result.setCode(ResultStatus.NOLOGIN);
            result.setErrMsg("用户未登录");
            return result;
        }

    public  static Result fail(String msg){
        Result result = new Result<>();
        result.setCode(ResultStatus.FAIL);
        result.setErrMsg(msg);
        return result;
    }
    public  static Result fail(String msg,ResultStatus resultStatus){
        Result result = new Result<>();
        result.setCode(resultStatus);
        result.setErrMsg(msg);
        return result;
    }

  }

